package com.atguigu.gmall;

import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.util.ClassUtils;

/**
 * @author: 李旭
 * @create: 2021-08-25 11:12
 *
 *   测试  FastDFS 上传文件
 *
 *
 **/
public class FastDFSDemo {

    public static void main(String[] args) throws Exception{
     /*   D:\IdeaProjects\gmall-210322\gmall-parent\service
      \service-product\src\main\resources\fdfs_client.conf*/
        String path = ClassUtils.getDefaultClassLoader().
                getResource("fdfs_client.conf").getPath();
        //0:设置跟踪器的IP：PORT     init:IO流取配置文件   只认绝对路径 不认相对路径
        ClientGlobal.init(path);
        //1:客户端连接跟踪器
        TrackerClient trackerClient = new TrackerClient();
        //2:获取存储节点的IP：PORT
        TrackerServer trackerServer = trackerClient.getConnection();
        //3:连接存储节点
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,null);

        //4:上传图片
        String fileId = storageClient1.upload_file1(
                "D:\\尚品汇商城\\资料\\图片\\小米Redmi K30\\8bda56c1434e9380.jpg"
                , "jpg", null);

        System.out.println(fileId);

        //  http://192.168.200.138:8080/group1/M00/00/00/wKjIimEmKgiANDqKAAKNYXoWRRA481.jpg
    }
}
